<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>注册__autoload()函数</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.spl-autoload-functions.html">spl_autoload_functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.spl-autoload-unregister.html">spl_autoload_unregister</a></div>
 <div class="up"><a href="ref.spl.html">SPL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.spl-autoload-register" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">spl_autoload_register</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2)</p><p class="refpurpose"><span class="refname">spl_autoload_register</span> &mdash; <span class="dc-title">注册__autoload()函数</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.spl-autoload-register-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>spl_autoload_register</strong></span>
    ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.callback" class="type callback">callback</a></span> <code class="parameter">$autoload_function</code></span>
  ] )</div>

  <p class="para rdfs-comment">
  将函数注册到SPL __autoload函数栈中。如果该栈中的函数尚未激活，则激活它们。
  </p>
  <p class="para">
  如果在你的程序中已经实现了__autoload函数，它必须显式注册到__autoload栈中。因为
  spl_autoload_register()函数会将Zend Engine中的__autoload函数取代为spl_autoload()或spl_autoload_call()。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.spl-autoload-register-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">autoload_function</code></em></dt>

     <dd>

      <p class="para">
       欲注册的自动装载函数。如果没有提供任何参数，则自动注册autoload的默认实现函数<span class="function"><a href="function.spl-autoload.html" class="function">spl_autoload()</a></span>。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.spl-autoload-register-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>



 <div class="refsect1 changelog" id="refsect1-function.spl-autoload-register-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.0</td>
       <td>
        Namespaces support was introduced.
       </td>
      </tr>

      <tr>
       <td>5.3.0</td>
       <td>
        The <em><code class="parameter">prepend</code></em> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.spl-autoload-register-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3825">
    <p><strong>Example #1 <span class="function"><strong>spl_autoload_register()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">namespace&nbsp;</span><span style="color: #0000BB">Foobar</span><span style="color: #007700">;<br /><br />class&nbsp;</span><span style="color: #0000BB">Foo&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">'[['</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$name&nbsp;</span><span style="color: #007700">.</span><span style="color: #DD0000">']]'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">spl_autoload_register</span><span style="color: #007700">(</span><span style="color: #0000BB">__NAMESPACE__&nbsp;</span><span style="color: #007700">.</span><span style="color: #DD0000">'::Foo::test'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;As&nbsp;of&nbsp;PHP&nbsp;5.3.0<br /><br /></span><span style="color: #007700">new&nbsp;</span><span style="color: #0000BB">InexistentClass</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
[[Foobar::InexistentClass]]
Fatal error: Class &#039;Foobar::InexistentClass&#039; not found in ...
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.spl-autoload-register-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.autoload.html" class="function" rel="rdfs-seeAlso">__autoload()</a> - 尝试加载未定义的类</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.spl-autoload-functions.html">spl_autoload_functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.spl-autoload-unregister.html">spl_autoload_unregister</a></div>
 <div class="up"><a href="ref.spl.html">SPL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
